package server;
import server.Data;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Location extends UnicastRemoteObject implements LocationInterface
{
	/*private int ID;
	private String name;
	private int locationNum;
	private int stationNum;*/
	private Data data;
	
	public Location() throws RemoteException{
		/*super();
		ID = id;
		this.name = name;
		this.locationNum = locationNum;
		this.stationNum = stationNum;*/
		data=new Data();
		// TODO Auto-generated constructor stub
	}

	/*public int getID()throws RemoteException 
	{
		String sql;
		ResultSet rs=null;
		int staffNum=0;
		
		sql="select * from station where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				staffNum=rs.getInt("staffNum");
		}
			} catch (SQLException e) {

			e.printStackTrace();
			}
			
		return staffNum;
		return ID;
	}*/
	
	public String getName(int locationNum) throws RemoteException 
	{
		String sql;
		ResultSet rs=null;
		String name="";
		
		sql="select * from location where locationNum=" + locationNum;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				name=rs.getString("name");
		}
			} catch (SQLException e) {

			e.printStackTrace();
			}
			
		return name;
	}
	
	public int getStationNum(int locationNum)throws RemoteException 
	{
		String sql;
		ResultSet rs=null;
		int stationNum=0;
		
		sql="select * from location where locationNum=" + locationNum;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				stationNum=rs.getInt("stationNum");
		}
			} catch (SQLException e) {

			e.printStackTrace();
			}
			
		return stationNum;
	}
	
	public int getSize() throws RemoteException{
		String sql;
		ResultSet rs=null;
		int sum=0;
		
		sql="select count(*) as sum from location";
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				sum=rs.getInt("sum");
		}
			} catch (SQLException e) {

			e.printStackTrace();
			}
			
		return sum;
	}
	
}
